import request from '@/plugins/axios'


//上传图片
export function uploadFile(data,callback) {
    return request({
        url: '/sys/file/upload',
        method: 'post',
        onUploadProgress: (progressEvent) => {
            let num = progressEvent.loaded / progressEvent.total * 100 | 0;  //百分比
            callback(num)
        },
        data
    })
}

//上传删除
export function uploadRemove(data) {
    return request({
        url: '/sys/file/remove',
        method: 'post',
        data
    })
}

export function uploadEditUploadImg(file, type) {
    let formData = new FormData();
    formData.append("file", file);
    formData.append("type", type);
    return request({
        url: '/sys/file/upload',
        method: 'post',
        data: formData,
        config: {
            headers: {
                'Content-Type': 'multipart/form-data'
            }
        }
    })
}

// 上传分片
export function uploadChunk(file, chunk, chunks, md5) {
    let formData = new FormData();
    formData.append("file", file);
    formData.append("chunk", chunk);
    formData.append("chunks", chunks);
    formData.append("md5", md5);
    return request({
        url: '/projectFile/v1/uploadChunk',
        method: 'post',
        timeout: 20 * 1000,
        data: formData,
        config: {
            headers: {
                'Content-Type': 'multipart/form-data'
            }
        }
    })
}
// 合并分片
export function mergeChunk(md5, size, contentType, chunks, filename) {
    let formData = new FormData();
    formData.append("md5", md5);
    formData.append("size", size);
    formData.append("contentType", contentType);
    formData.append("chunks", chunks);
    formData.append("filename", filename);
    return request({
        url: '/projectFile/v1/mergeChunk',
        method: 'post',
        data: formData,
        config: {
            headers: {
                'Content-Type': 'multipart/form-data'
            }
        }
    })
}
// 删除分片
export function deleteChunks(md5) {
    let formData = new FormData();
    formData.append("md5", md5);
    return request({
        url: '/projectFile/v1/deleteChunks',
        method: 'post',
        data: formData,
        config: {
            headers: {
                'Content-Type': 'multipart/form-data'
            }
        }
    })
}

export function deleteFile(md5) {
    let formData = new FormData();
    formData.append("md5", md5);
    return request({
        url: '/projectFile/v1/deleteFile',
        method: 'post',
        data: formData,
        config: {
            headers: {
                'Content-Type': 'multipart/form-data'
            }
        }
    })
}





